<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>刮刮乐</title>
</head>
<body onload="draw()">
  <img src="飞机大战/img/logo.png" alt="">
<canvas id="canvas" width="255" height="255" style="border: solid 1px #000;position: absolute;left: 0;"></canvas>
<script>
function draw(){
  let canvas = document.querySelector("#canvas");
  if(canvas.getContext){
    //创建context对象
    let cvsCtx = canvas.getContext("2d");
    //灰色盖住图片
    cvsCtx.beginPath();
    cvsCtx.fillStyle = "#ccc";
    cvsCtx.fillRect(0, 0, canvas.width, canvas.height);

    cvsCtx.globalCompositeOperation = "destination-out";
    cvsCtx.lineCap = 'round';
    cvsCtx.lineWidth = "20"
    //鼠标按下
    canvas.onmousedown = function(e){
      let ev = e || window.event;
      let x = ev.clientX - canvas.offsetLeft;
      let y = ev.clientY - canvas.offsetTop;

      cvsCtx.moveTo(x, y);
      //移动
      canvas.onmousemove = function(e){
        let ev = e || window.event;
        let x = ev.clientX - canvas.offsetLeft;
        let y = ev.clientY - canvas.offsetTop;
        cvsCtx.lineTo(x, y);
        cvsCtx.stroke();
      }
      
    }
    //弹起
    canvas.onmouseup = function(){
        canvas.onmousemove = null;
    }

  }
}
</script>
</body>
</html>